﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web;
using System.Web.Mvc;
using Persons.Interfaces;
using Persons.DS;
using Persons.Classes;

namespace WebApplicPersons.Controllers
{
    public class ListOfPersonsController : Controller
    {
        //
        // GET: /ListOfPersons/
        static ListOfPersons list = new ListOfPersons(new DS_MOCK());

        public ActionResult List()
        {
            var viewModel = list.Read().ToList();
            return View(viewModel);
        }

        public ActionResult Create()
        {
            var viewModel = new Persona();
            return View(viewModel);
        }
        [HttpPost]
        public ActionResult Create(Persona persona)
        {
            list.Create(persona);
            return RedirectToAction("List");
        }
        public ActionResult Delete(int id)
        {
            var persona = list.Single(a => a.ID == id);
            return View(persona);
        }
        [HttpPost]
        public ActionResult Delete(int id, string confirmButton)
        {
            list.Delete(id);
            return RedirectToAction("List");
        }
        public ActionResult Edit(int id)
        {
            var persona = list.Single(a => a.ID == id);
            return View(persona);
        }
        [HttpPost]
        public ActionResult Edit(Persona per, FormCollection formValues, HttpPostedFileBase image)
        {
            //var persona = list.Single(a => a.ID == per.ID);
            list.Update(per);
            return RedirectToAction("List");
            
        }

    }
}
